package com.java.base.exercise.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Author RenPu
 * @Date 2022/7/13 15:55
 * @Version 1.0
 * @Description: JDk代理类编写方式
 **/
public class JDKProxy {

    public static <T> T getProxy(Class clazz){
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        return (T) Proxy.newProxyInstance(classLoader, new Class[]{clazz}, new InvocationHandler() {
            @Override
            public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
                System.out.println(method.getName() + " 你被代理了，By JDKProxy！");
                return "小傅哥，公众号：bugstack虫洞栈 | 沉淀、分享、成长，让自己和他人都能有所收获！";
            }
        });
    }


}
